package ControlLayer;
import java.util.ArrayList;
import ModelLayer.*;
//model layer package has to be imported
/**
 * Controller class for the DVD collection
 * 
 * @author (kbh) 
 * @version (2005.03.31)
 * @revised version English (Ab)
 * (FEN): 2006.03.21: Some changes to the architecture in order to assure layering
 *                    and loose coupling
 */
public class DVDCtr
{
    private DVD_Register collection;
    //passed as arguments from the main class

    /**
     * Constructor for objects of class DVDCtr
     */
    public DVDCtr()//DVD container is to be passed as parameter from the main controller
    {
        collection=DVD_Register.getInstance();
        
    }
    
    //Dummy implementation: after implementing the model layer 
    //objects of class DVD are to be returned, not String
    public DVD findDVD( String title )
    {
       return collection.findDVD(title);
    }
    
    //Dummy implementation: more parameters are probaly to added
    public void createDVD(String id, String title, String artist, String publicationDate)
    {
         if(findDVD(title)!= null){
            System.out.println("DVD with title: "+title+" already exists");
         }else{
             
         collection.addDVD(id,title,artist,publicationDate);
        }
    }
    
    //Deletes DVD from container according DVD's title.
    public void deleteDVD(String title)
    {
        if(findDVD(title)==null){
            System.out.println("Can't delete "+title+" DVD. It doesn't exist");
        }else{
            collection.removeDVD(title);
            System.out.println("DVD "+title+" was successfully deleted.");
        }
    }
    
    
    public void listAllDvds()
    {
          //returns a list of all dvds and their associated copies
          if(collection.showDVDS().isEmpty()){
            System.out.println("There's no list of DVDS at the time");
          }
          int index=0;
        while(index<collection.showDVDS().size())
        {
            System.out.println(collection.showDVDS().get(index).toString());
            System.out.println("This DVD has " + collection.showDVDS().get(index).copiesCollection().size() +" copies");
            int i=0;
            while (i<collection.showDVDS().get(index).copiesCollection().size())
            {
                int k=i+1;
                System.out.println("Copy nr."+k);
                System.out.println(collection.showDVDS().get(index).copiesCollection().get(i).toString());
            i++;
            }
            System.out.println("___________________________________________________________");
            
            index++;
        }
    }
   //Updates DVD information
    public void update(String id, String title, String artist, String publicationDate){
        if(findDVD(title)==null){
            System.out.println("Can't update. "+title+" doesn't exist.");
        }else{
        collection.updateInformation(id, title, artist, publicationDate);
        }
    }
    //Creates one copy of DVD per time
    public void createCopy(String DVDtitle,String serialNumber, String purchaseDate, String purchasePrice)
    {
        if(findDVD(DVDtitle).findCopy(serialNumber)==null){
         findDVD(DVDtitle).createCopy(serialNumber,purchaseDate, purchasePrice);
        }else{
            System.out.println("Such copy already exists.");
        }
    }
    
    //Updates copy information
    public void updateCopy(String DVDtitle, String serialNumber, String purchaseDate, String purchasePrice){
        if(findDVD(DVDtitle).findCopy(serialNumber)!=null){
            System.out.println("Such copy already exists.");
        }
        findDVD(DVDtitle).update(serialNumber,purchaseDate, purchasePrice);
    }
    //deletes Copy
    public void deleteCopy(String DVDtitle, String serialNumber){
        if(findDVD(DVDtitle).findCopy(serialNumber)!=null){
        findDVD(DVDtitle).removeCopy(serialNumber);
        }else{
            System.out.println("Such copy doesn't exists");
        }
    }
    //finds Copy of certain DVD
    public void findCopy(String DVDtitle, String serialNumber){
        if(findDVD(DVDtitle).findCopy(serialNumber)!=null){
        findDVD(DVDtitle).findCopy(serialNumber);
        }else{
            System.out.println("Could not find such copy.");
        }
    }
}
